package org.ruslan.kolobok;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;

public class GraphicUtils {

	public static final int XY = 1;
	public static final int XZ = 2;

	private GraphicUtils() {
		// utility class
	}

	public static void drawAxis(ShapeRenderer shapeRenderer, float halfLen) {

		// X (green)
		shapeRenderer.begin(ShapeType.Line);
		shapeRenderer.setColor(0.0f, 1.0f, 0.0f, 0.0f);
		shapeRenderer.line(-halfLen, 0.0f, halfLen, 0.0f);

		// Y (blue)
		shapeRenderer.setColor(0.0f, 0.0f, 1.0f, 0.0f);
		shapeRenderer.line(0.0f, -halfLen, 0.0f, halfLen);

		// Z (red)
		shapeRenderer.setColor(1.0f, 0.0f, 0.0f, 0.0f);
		shapeRenderer.line(0.0f, 0.0f, -halfLen, 0.0f, 0.0f, halfLen);
		shapeRenderer.end();
	}

	public static void drawGrid(ShapeRenderer shapeRenderer, float halfLen,
			float step, int flag) {

		float i;

		Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA,
				GL10.GL_ONE_MINUS_SRC_ALPHA);
		Gdx.gl.glEnable(GL10.GL_BLEND); // Enable Blending

		shapeRenderer.begin(ShapeType.Line);
		shapeRenderer.setColor(0.5f, 0.5f, 0.5f, 0.5f);
		for (i = 0; i < halfLen; i += step) {

			if ((flag & XY) != 0) {
				// XY

				shapeRenderer.line(-halfLen, i, halfLen, i);
				shapeRenderer.line(-halfLen, -i, halfLen, -i);

				shapeRenderer.line(i, -halfLen, i, halfLen);
				shapeRenderer.line(-i, -halfLen, -i, halfLen);
			}

			if ((flag & XZ) != 0) {
				// XZ
				shapeRenderer.line(-halfLen, 0, i, halfLen, 0, i);
				shapeRenderer.line(-halfLen, 0, -i, halfLen, 0, -i);
				shapeRenderer.line(i, 0, -halfLen, i, 0, halfLen);
				shapeRenderer.line(-i, 0, -halfLen, -i, 0, halfLen);
			}
		}
		shapeRenderer.end();
		Gdx.gl.glDisable(Gdx.gl10.GL_BLEND);
	}

}
